# Contributor: gay <gay@disroot.org>
# Maintainer: Celeste <cielesti@protonmail.com>
pkgname=darcs
pkgver=2.18.2
pkgrel=0
pkgdesc="Patch-based revision control system"
url="https://darcs.net/"
arch="aarch64 x86_64" # limited by ghc
license="GPL-2.0-or-later"
makedepends="cabal ghc curl-dev ncurses-dev zlib-dev"
#checkdepends="diffutils grep lighttpd musl-locales"
options="!check" # tests relying on presence of shell utils fail without giving detailed log
subpackages="$pkgname-doc"
source="https://hackage.haskell.org/package/darcs-$pkgver/darcs-$pkgver.tar.gz
	cabal.project.freeze
	"

# Directory where cabal files are stored.
export CABAL_DIR="$srcdir/dist"

# Needed to fix build on aarch64.
export PATH="$PATH:/usr/lib/llvm15/bin"

cabal_update() {
	cd $builddir
	cabal v2-update
	(
		cd "$builddir"
		cabal v2-freeze --shadow-installed-packages
		mv cabal.project.freeze "$startdir/"
	)
}

prepare() {
	default_prepare
	ln -sf "$srcdir/cabal.project.freeze" \
		"$builddir/cabal.project.freeze"
}

build() {
	cabal v2-update
	cabal v2-build darcs:exes \
		--jobs=${JOBS:-1} \
		--prefix=/usr \
		--docdir=/usr/share/doc/$pkgname \
		--sysconfdir=/etc
}

check() {
	cabal test
}

package() {
	cd dist-newstyle/build/*-linux/ghc-*/$pkgname-$pkgver/build/$pkgname
	install -Dm755 $pkgname "$pkgdir"/usr/bin/$pkgname
	install -Dm644 $pkgname.1 "$pkgdir"/usr/share/man/man1/$pkgname.1
}

sha512sums="
f776b3b2efd73e9515a99bf154468aa4aef925d20c9de564a78f7a19bf302db31c6e4cdbca2c2c700a0d5cde1b62a426159554f543898712b1f603401c534a9c  darcs-2.18.2.tar.gz
b177b661b37a907db1af30e6f796a5c2f600bc8b19411b3a741b071a45ee257a2371e160ea7c1cc31b07a288f2aa9966a14318ca1c0c0eede6aa11fe81798de9  cabal.project.freeze
"
